<?php
session_start();
header('Content-Type: text/html; charset=UTF-8');
require ("sql.php");
if ( !$_SESSION['user_id'] )
{ 
echo "Bạn chưa đăng nhập! <a href='login.php'>Nhấp vào đây để đăng nhập</a> "; 
}
else{
$user_id = ($_SESSION['user_id']);
$sql_query = @mysql_query("SELECT * FROM user WHERE tai_khoan='{$user_id}'");
$user = @mysql_fetch_array( $sql_query ); 
?>
 <?php if ($user['admin']=="3") echo" <a> bạn không có quyền truy cập vào trang này</a>";
else { ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Thêm Điểm</title>
</head>


<body>

<a style="float:right" href="index.php">Quay lại trang chủ</a>
<?php 

mysql_query("SET NAMES 'utf8'");
require ("sql.php");
$result1=mysql_query("SELECT * FROM mon");
$result2=mysql_query("SELECT * FROM hk");
?>

<?php
  if ( $_GET['act'] == "do" )
  {
$diem_mieng= $_POST[ "diem_mieng"];
$diem_15p= $_POST[ "diem_15p"];
$diem_bs1= $_POST[ "diem_bs1"];
$diem_bs2= $_POST[ "diem_bs2"];
$diem_1tiet1= $_POST[ "diem_1tiet1"];
$diem_1tiet2= $_POST[ "diem_1tiet2"];
$diem_thi= $_POST[ "diem_thi"];
$m_mh = $_POST["m_mh"];
$m_hk = $_POST["m_hk"];
$m_hs = $_POST["m_hs"];
$sql_query = @mysql_query("SELECT m_hs FROM hs WHERE m_hs='{$m_hs}'");
$user = @mysql_fetch_array( $sql_query );
if ( @mysql_num_rows( $sql_query ) <= 0 )
{
print "Mã học sinh không đúng <a href='javascript:history.go(-1)'>Quay trở lại</a>";
exit;
}
$result= @mysql_query("INSERT INTO diem (m_hs,m_mh,diem_mieng,diem_15p,diem_bs1,diem_bs2,diem_1tiet1,diem_1tiet2,diem_thi,m_hk) VALUES 
('{$m_hs}','{$m_mh}','{$diem_mieng}','{$diem_15p}','{$diem_bs1}','{$diem_bs2}','{$diem_1tiet1}','{$diem_1tiet1}','{$diem_thi}','{$m_hk}')");
if($result) 
{
	echo " them sua thanh cong";
	echo "<a href='javascript:history.go(-1)'>Quay trở lại tiếp tục nhập điểm</a>";
}
else

	echo "kiem tra lai thong tin";
	echo mysql_error();
}
else
{
echo"<form action='themdiem.php?act=do' method='post' name='form1' >";
echo "Mã học sinh: <input type='text' name='m_hs' id='ma_hs' style='width:70px;'/>";
//echo "<br> Họ Tên <input style='margin-left:31px' type='text' name='ten' style='width:120px;'/>";
echo "<br><h2>Điểm</h2>";
echo"<table border='2' align='center' cellpadding='1' cellspacing='5'>";
echo"<tr>";
		echo"<td width='80'>Mã môn</td>";
		echo"<td width='80'>Điểm miệng</td>";
		echo"<td width='80'>Điểm 15 phút</td>";
		echo"<td width='80'>Điểm bổ sung 1</td>";
		echo"<td width='80'>Điểm bổ sung 2</td>";
		echo"<td width='80'>Điểm 1 tiết 1</td>";
		echo"<td width='80'>Điểm 1 tiết 2</td>";
		echo"<td width='80'>Điểm thi</td>";
		echo"<td width='80'>Mã học kỳ</td>";
	echo"</tr>";
 echo"<tr>";
		//echo"<td><select name='m_mh'> id='m_mh' "; while($row=mysql_fetch_row($result1)){ echo "<option value=$row[0]>$row[0]</option>";} echo"</select></td>";
		echo"<td><select name='m_mh'> id='m_mh' <option value=hoa>hoá</option><option value=ly>lý</option><option value=Tienganh>Tiếng anh</option><option value=toan>toán</option><option value=van>văn</option> </select></td>";
		echo"<td><input style='width:100px;' type='text' name='diem_mieng' id='diem_mieng' value='0'/></td>";
		echo"<td><input style='width:100px;' type='text' name='diem_15p' id='diem_15p' value='0'/></td>"; 
		echo"<td><input style='width:100px;' type='text' name='diem_bs1' id='diem_bs1' /></td>";
		echo"<td><input style='width:100px;' type='text' name='diem_bs2' id='diem_bs2' /></td>";
		echo"<td><input style='width:100px;' type='text' name='diem_1tiet1' id='diem_1tiet1' value='0'/></td>";
		echo"<td><input style='width:100px;' type='text' name='diem_1tiet2' id='diem_1tiet2' value='0'/></td>";
		echo"<td><input style='width:100px;' type='text' name='diem_thi' id='diem_thi' value='0'/></td>";
		//echo"<td><select name='m_hk' id='ma_hk'>"; while($row1=mysql_fetch_row($result2)){ echo "<option value=$row1[0]>$row1[0]</option>";} echo"</select></td>";
		echo"<td><select name='m_hk'> id='m_hk' <option value=12a>12a</option><option value=12b>12b</option><option value=13a>13a</option><option value=13b>13b</option> </select></td>";

echo"</tr>"; 
echo "</table>";
echo "<br> <input style='margin-left:600px' type='submit' name='submit' value='Nhập'>";
echo"</form>";
}
}
}
?>

</body>
</html>